Skip to content

[Messenger] get() usage #11889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2019
Merged

[Messenger] get() usage #11889

merged 1 commit into from
Sep 26, 2019

Conversation

Guikingone
Copy link
Contributor

Hi everyone 👋

As noticed here #11861 (comment) by @xabbuh, a small error has been found in the get() documentation.

This PR contains a small improvement.

@javiereguiluz javiereguiluz added this to the 4.3 milestone Jul 4, 2019

return [$envelope];

// Reject the message if needed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment ... should we add another (commented) line of code showing how to reject the message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is linked to the transport, I don't know if we can find a generic approach, I've added one if you want to check it 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I can't review because I don't understand this ... but as a reader, the comment was strange because it was like "you can reject the message if you want" OK but here? now? how? is the comment related to the following return? Returning means rejecting? etc.

Copy link
Contributor Author

@Guikingone Guikingone Jul 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, sorry for the wording.

As get() allows you to receive a message and decide if you want to send it to the application, reject it or ack it, the core logic of the get() method is to decide the next step.

As done in the RedisReceiver:

/**
     * {@inheritdoc}
     */
    public function get(): iterable
    {
        $redisEnvelope = $this->connection->get();
        if (null === $redisEnvelope) {
            return [];
        }
        try {
            $envelope = $this->serializer->decode([
                'body' => $redisEnvelope['body'],
                'headers' => $redisEnvelope['headers'],
            ]);
        } catch (MessageDecodingFailedException $exception) {
            $this->connection->reject($redisEnvelope['id']);
            throw $exception;
        }
        return [$envelope->with(new RedisReceivedStamp($redisEnvelope['id']))];
    }

You can say: If there's an error (Doctrine try to catch the DbalException for example), so I need to reject the message (maybe because of it's content or other factors).

If the message is rejected, the transport handles the next step.

When we say return [$yourEnvelope->with(new CustomStamp($yourEnvelope['id']);, we make the message available for the application 🙂

Hope it helps 🙂

javiereguiluz added a commit that referenced this pull request Sep 26, 2019
This PR was squashed before being merged into the 4.3 branch (closes #11889).

Discussion
----------

[Messenger] `get()` usage

Hi everyone 👋

As noticed here #11861 (comment) by @xabbuh, a small error has been found in the `get()` documentation.

This PR contains a small improvement.

Commits
-------

5ccad7f [Messenger] `get()` usage
@javiereguiluz javiereguiluz merged commit 5ccad7f into symfony:4.3 Sep 26, 2019
@javiereguiluz
Copy link
Member

Thanks @Guikingone! I did the fix suggested by @Leprechaunz while merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants